package com.botann.projects.model;

import com.botann.projects.annotations.Expand;
import com.botann.projects.base.BaseService;
import com.botann.projects.utils.ModelUtils;
import com.botann.projects.annotations.Expand;
import com.botann.projects.base.BaseService;
import com.botann.projects.utils.ModelUtils;

import javax.persistence.*;
import java.util.Date;

/**
 * server-simple
 * AdminUser
 * Created by 刘山国 on 2019/10/15.
 * Copyright (c) 2017 伯坦科技. All rights reserved
 */
@Entity
@Table(name = "admin_user", schema = "db_server_simple", catalog = "")
public class AdminUser {
    private int id;
    private String username;
    private String password;
    private String name;
    private String phone;
    private int roleId;
    private Date createTime;
    private boolean del;

    // Role
    @Expand(value = "r", name = "name")
    private String roleName;
    @Expand("r")
    private int rank;
    @Expand("r")
    private String authority;

    public static StringBuilder expandJoinBuilder(){
        return BaseService.selectNewBuilder(AdminUser.class)
                .append(ModelUtils.getFieldsE(AdminUser.class,"a"))
                .append(") ")
                .append(" from AdminUser a")
                .append(" inner join Role r on a.roleId=r.id ");
    }

    public AdminUser() {
    }

    public AdminUser(int id, String username, String password, String name, String phone, int roleId, Date createTime, boolean del, String roleName, int rank, String authority) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.name = name;
        this.phone = phone;
        this.roleId = roleId;
        this.createTime = createTime;
        this.del = del;
        this.roleName = roleName;
        this.rank = rank;
        this.authority = authority;
    }

    @Id
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "username", nullable = false, length = 64)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    @Column(name = "password", nullable = false, length = 128)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "name", nullable = false, length = 32)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "phone", nullable = false, length = 16)
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Basic
    @Column(name = "role_id", nullable = false)
    public int getRoleId() {
        return roleId;
    }

    public void setRoleId(int roleId) {
        this.roleId = roleId;
    }

    @Basic
    @Column(name = "create_time", nullable = false)
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "del", nullable = false)
    public boolean isDel() {
        return del;
    }

    public void setDel(boolean del) {
        this.del = del;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AdminUser adminUser = (AdminUser) o;

        if (id != adminUser.id) return false;
        if (roleId != adminUser.roleId) return false;
        if (del != adminUser.del) return false;
        if (username != null ? !username.equals(adminUser.username) : adminUser.username != null) return false;
        if (password != null ? !password.equals(adminUser.password) : adminUser.password != null) return false;
        if (name != null ? !name.equals(adminUser.name) : adminUser.name != null) return false;
        if (phone != null ? !phone.equals(adminUser.phone) : adminUser.phone != null) return false;
        if (createTime != null ? !createTime.equals(adminUser.createTime) : adminUser.createTime != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + roleId;
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (del ? 1 : 0);
        return result;
    }
}
